<template>
<div class="PrintReplace overflowY"   v-loading="loading">
  <!--<div class="PageTitle"><i class="iconfont icon-jia"></i>火化证打印补办</div>-->
  <div class="PageContent">
    <object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0> 
      <embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0></embed>
    </object>
    <el-form :model="ruleForm" :rules="rules" :inline="true" ref="PrintReplaceruleForm" label-width="120px" class="demo-ruleForm" @submit.native.prevent>
      <div class="PageItem margintop20">
        <el-row :gutter="0"  class="paddingleft2">
          <el-form-item  label="业务编码:" >
            <el-input  v-model="businessCode" ref="printbusinessCode" @keyup.enter.native="searchData(businessCode)" :maxlength="20" placeholder="请输入业务编码"
                style="width:230px">
              <el-button
                  slot="append"
                  icon="el-icon-circle-close"
                  @click="businessCode=''"
                ></el-button>
              <el-button type="primary" slot="append" icon="el-icon-search" v-if="btnRight.btnPrintReplaceCodeScanning" @click="searchData(businessCode)"></el-button>
            </el-input>
          </el-form-item>

          <el-button type="primary"    v-if="btnRight.btnBusinessSearch"  @click="businessSearchShow()">业务查询</el-button>
          <el-form-item label="业务编码:" >
            <span  class="titlecont">{{ruleForm.funeralDead.businessCode}}</span>
          </el-form-item>
          <el-form-item label="逝者姓名:">
            <span class="titlecont">{{ruleForm.funeralDead.deadName}}</span>
          </el-form-item>
          <el-form-item label="减免类型:">
            <span class="titlecont">{{ruleForm.funeralDead.exemptionType}}</span>
          </el-form-item>
          <el-form-item label="家属姓名:" >
            <span class="titlecont">{{ruleForm.familyMember.memberName}}</span>
          </el-form-item>
          <i class="el-icon-arrow-down more" v-if="!moreFlag" @click="moreFlag=!moreFlag">&nbsp;展开</i>
          <i class="el-icon-arrow-up more" v-if="moreFlag" @click="moreFlag=!moreFlag">&nbsp;收起</i>
        </el-row>
      </div>
      <div class="PageItem " v-if="moreFlag">
        <el-row class="PageInfo"><i class="info-bar"></i>逝者基本信息</el-row>
        <el-row :gutter="0"  class="paddingleft2">
          <el-form-item label="业务编码:" >
            <span  class="cont">{{ruleForm.funeralDead.businessCode}}</span>
          </el-form-item>
          <el-form-item label="逝者姓名:" >
            <span  class="cont">{{ruleForm.funeralDead.deadName}}</span>
          </el-form-item>
          <el-form-item label="证件号码:" >
            <span  class="cont">{{ruleForm.funeralDead.certificateNo}}</span>
          </el-form-item>
          <el-form-item label="性别:" >
            <span  class="cont">{{ruleForm.funeralDead.deadGender}}</span>
          </el-form-item>
        </el-row>
        <el-row :gutter="0"  class="paddingleft2">
          <el-form-item label="减免区域:">
            <span class="cont">{{ ruleForm.funeralDead.benefitDistrict }}</span>
          </el-form-item>
          <el-form-item label="减免类型:" >
            <span class="cont" >{{ruleForm.funeralDead.exemptionType}}</span>
          </el-form-item>
          <el-form-item label="接尸地点:" >
            <span  class="cont">{{ruleForm.funeralDead.transportPlace}}</span>
          </el-form-item>
          <el-form-item label="火化证号:" >
            <span  class="cont">{{ruleForm.cremation.cremationNo}}</span>
          </el-form-item>
        </el-row>
        <el-row class="PageInfo"><i class="info-bar"></i>家属基本信息</el-row>
        <el-row :gutter="0"  class="paddingleft2">
          <el-form-item label="家属姓名:" >
            <span  class="cont">{{ruleForm.familyMember.memberName}}</span>
          </el-form-item>
          <el-form-item label="证件号码:" >
            <span  class="cont">{{ruleForm.familyMember.certificateNo}}</span>
          </el-form-item>
          <el-form-item label="与逝者关系:">
            <span  class="cont">{{ruleForm.familyMember.memberRelation}}</span>
          </el-form-item>
          <el-form-item label="联系方式:" >
            <span  class="cont">{{ruleForm.familyMember.mobilePhone}}</span>
          </el-form-item>
        </el-row>
        <el-row class="PageInfo"><i class="info-bar"></i>承办人基本信息</el-row>
        <el-row :gutter="0"  class="paddingleft2">
        <el-form-item label="承办人姓名:" >
          <span  class="cont">{{ruleForm.familyAgent.agentName}}</span>
        </el-form-item>
        <el-form-item label="证件号码:" >
          <span  class="cont">{{ruleForm.familyAgent.certificateNo}}</span>
        </el-form-item>
        <el-form-item label="与逝者关系:" >
          <span  class="cont">{{ruleForm.familyAgent.agentRelation}}</span>
        </el-form-item>
        <el-form-item label="联系方式:" >
          <span  class="cont">{{ruleForm.familyAgent.mobilePhone}}</span>
        </el-form-item>
      </el-row>
      </div>

      <div class="PageItem ">
        <el-row class="PageInfo"><i class="info-bar"></i>火化证打印补办</el-row>
        <el-row :gutter="0"  class="paddingleft2">
          <el-form-item label="操作类型:"  prop="name"  class="marginright50">
            <el-select v-model="saveCertificate.operationTypeCode" @change="operationType(saveCertificate.operationTypeCode)" placeholder="请选择"  style="width: 120px;">
              <el-option label="补打" value="3" ></el-option>
            </el-select>
          </el-form-item>
        </el-row>
        <el-row :gutter="0"  class="paddingleft2">
        <el-form-item label="原因:" class="textarea" v-if="saveCertificate.operationTypeCode!='2'">
          <el-input type="textarea" v-model="saveCertificate.operationCause" ></el-input>
        </el-form-item>
          <el-form-item label="原因:" class="textarea" v-else-if="saveCertificate.operationTypeCode=='2'" prop="cause">
            <el-input type="textarea" v-model="saveCertificate.operationCause" ></el-input>
          </el-form-item>
      </el-row>
      </div>
      <el-row class="PageItem" style="text-align:right;margin:30px 0;">
        <el-button type="primary"  plain @click="loadChargeSettledByBusinessCode">打印收费明细</el-button>
        <el-button type="primary"  v-if="btnRight.btnRePrintCremationCert"  @click="rePrintCert"  class="marginright50">补打火化证</el-button>
        <el-button type="primary"  @click="saveData" :disabled="saveFlag" class="marginright50">保存并打印火化证</el-button>
        <el-button type="primary" plain v-if="btnRight.btnPrintReplacePhotoRecord" @click="PhotoArchival">拍照备案</el-button>
      </el-row>
      <div class="PageItem ">
      <el-row class="PageInfo"><i class="info-bar"></i>打印历史记录</el-row>
      <el-table
        :data="ruleForm.printHistory"
        :header-cell-style="{background:'rgb(246,247,251)',color:'#606266'}"
        stripe
        border
        style="width: 100%;">
        <el-table-column align = 'center'  prop="operationTime"  label="打印日期"  width="200">
        </el-table-column>
        <el-table-column
          prop="operationType"
          align = 'center'
          label="操作类型"
          width="100">
        </el-table-column>
        <el-table-column
          prop="cremationNewNo"
          align = 'center'
          label="新火化证号"
          width="200">
        </el-table-column>
        <el-table-column
          prop="cremationOldNo"
          align = 'center'
          label="原火化证号"
          width="200">
        </el-table-column>
        <el-table-column
          prop="address"
          align = 'center'
          label="家庭住址">
        </el-table-column>
        <el-table-column
          prop="operationCause"
          align = 'center'
          label="原因"
          width="150">
        </el-table-column>
        <el-table-column
          prop="memberGender"
          align = 'center'
          label="性别"
          width="120">
        </el-table-column>

        <el-table-column
          prop="mobilePhone"
          align = 'center'
          label="手机号码"
          width="100">
        </el-table-column>
        <el-table-column
          prop="certificateType"
          align = 'center'
          label="证件类型"
          width="200">
        </el-table-column>
        <el-table-column
          prop="certificateNo"
          align = 'center'
          label="证件号码"
          width="200">
        </el-table-column>
        <el-table-column
          prop="memberRelation"
          align = 'center'
          label="与逝者关系"
          width="150">
        </el-table-column>
        <el-table-column
          prop="address"
          align = 'center'
          label="家庭住址">
        </el-table-column>
      </el-table>
      </div>
    </el-form>
  </div>

  <SearchDialog :DialogSearch="DialogSearch" :copyCremationTypes="dictionary.cremation_type"></SearchDialog>
</div>
</template>

<script>
  import * as Type from '@/api/service'
  import {dataFormate, dataFormatetmd,dataFormatetmd1} from '@/utils/index'
  import {getLodop} from '@/utils/lodopFuncs'
  import SearchDialog from '../dialog/SearchDialog'
    export default {
      name: "replacePrintCremation",
      components: {
        SearchDialog,
      },
      inject:['reload'],
      data(){
        return{
          DialogSearch: false, //业务查询
          printTypes:[
            {label:"补打",value: 3}
          ],
          loading:false,
          saveFlag: false,     //保存过程中不可更改,true为正在保存
          onpresscTime:0,  //  阻止短时间内连续点击
          rules: {
            name: [
              { required: true, message: '请选择操作类型', trigger: 'blur' },
            ],
            cause:[
              { required: true, message: '请填写原因', trigger: 'change' },
            ]
          },

          operationCause:"", //原因
          businessCode:"",
          moreFlag:false,    //折叠
          cremation:{//火化任务
            id:0,
            cremationVersion:0
          },//火化任务
          ruleForm: {
            "funeralDead": {
              "id": 0,
              "businessCode": "",
              "deadName": "",
              "certificateNo": "",
              "deadGender": "",
              "benefitDistrict": "",
              "exemptionType": "",
              "transportPlace": "",
              "version": 0
            },
            "familyMember": {
              "id": 0,
              "memberName": "",
              "memberGenderCode": 0,
              "memberGender": "",
              "mobilePhone": "",
              "otherPhone": "",
              "address": "",
              "certificateTypeCode": 0,
              "certificateNo": "",
              "memberRelation": "",
              "version": 0
            },
            "familyAgent": {
              "id": 0,
              "agentType": 0,
              "agentUnitName": "",
              "agentName": "",
              "mobilePhone": "",
              "otherPhone": "",
              "certificateNo": "",
              "agentRelation": "",
              "version": 0
            },
            "cremation": {
              "id": 0,
              "cremationNo": "",
              "version": 0
            },
            "dicts": {
              "cremation_certificate_printing_operation_type": {
                "dataCode": 0,
                "dataText": "",
                "dataTextAbbr": "",
                "disableState": 0,
                "asDefault": 0
              }
            },
            "printHistory": [],
            "chargeSettles":[],
          },  //读取的数据
          saveCertificate:{ //要保存的数据
            "businessCode": "",
            "memberId": 0,
            "memberVersion": 0,
            "certificateTypeCode":"",
            "operationTypeCode": "",
            "operationTime": "",
            "operationCause": "",
            "cremationOldNo": "",
            "cremationNewNo": ""
          },
          dialogFormVisible:false,
          dictionary:{},
          btnPermisson:{},
          //按钮权限
          btnRight: {
            btnPrintReplaceCodeScanning: true,  //业务编码扫码按钮
            btnPrintReplaceCreateCode: true,    //生成火化证号
            btnPrintReplaceSaveAndPrint: true,  //保存并打印火化证
            btnRePrintCremationCert: true,  //补打火化证
            btnPrintReplacePhotoRecord: true,   //拍照备案
            btnBusinessSearch: true, //业务查询
          }
        }

      },
      mounted(){
        //默认操作类型下拉框为补打
        this.saveCertificate.operationTypeCode = "3";
        //按钮权限
        this.btnRight = this.$route.meta.buttons;
        //遍历属性赋值将true与false字符串转换成布尔型的值
        for (let key of Object.keys(this.btnRight)) {
          this.btnRight[key]=(this.btnRight[key]|| this.btnRight[key]=="true")?true:false;
        }
        this.$store.dispatch('user/getdictionary').then((res) => {     //获取字典数据
          this.dictionary = res;
          this.$set(this.dictionary,res)
          // console.log(this.dictionary.sex)
        }).catch(()=>console.log('promise catch err'))
        this.businessCode = this.$store.getters.businessCode
        if (this.businessCode) {
          this.searchData(this.businessCode)
        }
        this.btnPermisson = this.$route.meta.button;
        //businessCode获得焦点
        this.$refs["printbusinessCode"].focus()
      },
      methods:{
          digitUppercase(n) {
              var fraction = ['角', '分'];
              var digit = [
                  '零', '壹', '贰', '叁', '肆',
                  '伍', '陆', '柒', '捌', '玖'
              ];
              var unit = [
                  ['元', '万', '亿'],
                  ['', '拾', '佰', '仟']
              ];
              var head = n < 0 ? '欠' : '';
              n = Math.abs(n);
              var s = '';
              for (var i = 0; i < fraction.length; i++) {
                  s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
              }
              s = s || '整';
              n = Math.floor(n);
              for (var i = 0; i < unit[0].length && n > 0; i++) {
                  var p = '';
                  for (var j = 0; j < unit[1].length && n > 0; j++) {
                      p = digit[n % 10] + unit[1][j] + p;
                      n = Math.floor(n / 10);
                  }
                  s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;
              }
              return head + s.replace(/(零.)*零元/, '元')
                  .replace(/(零.)+/g, '零')
                  .replace(/^整$/, '零元整');
          },

          //查询已经结算的费用信息
          loadChargeSettledByBusinessCode() {
            let this_print = this;
            if (!this_print.businessCode || this_print.businessCode.length == 0) {
              this.$message("请输入业务编码");
              return;
            }
            let postData = {
              businessCode: this_print.businessCode,
            };

            //打印 已经结算的费用信息
            Type["loadChargeSettledByBusinessCode"](postData)
              .then((response) => {
                //接收返回数据
                let result = response.data;
                //调用打印接口
                this_print.printChargeSettledInfo(result);
              })
              .catch((error) => {
                this_print.$message(error.message);
              });
          },
          //打印结算清单明细
          printChargeSettledInfo(printData) {
            let this_print = this;
            let LODOP = getLodop();
            if (LODOP == null || !LODOP) {
              this_print.$.messager.alert(
                "系统提示",
                "您的浏览器不支持打印控件，请用IE重试或安装打印控件后重试"
              );
              return;
            }
            for (let key in printData) {
              printData[key] = printData[key] ? printData[key] : "　";
            }
            //二维码
            let recCode = printData[0].businessCode;
            //减免类型
            let jianMianType = "减免类型：" + "减免类型";
            //业务编码
            let businessCode = printData[0].businessCode;
            //付款方式
            let selltedType = printData[0].payType;
            //收费日期
            let businessTime = printData[0].chargeTime;
            //业务编码
            let title = "临沂市第二殡仪馆 费用已结算明细单";
            //逝者姓名
            let deadName = printData[0].deadName;
            //应收
            let itemCharges=0
            //优惠
            let discountCharge=0
            //减免
            let benefitCharge=0
            //实收
            let realityCharge=0
            //大写
            let big_realityCharge=''

            let chargeItems=printData.map(function(el){
              let {itemName,itemCharge}=el
              let obj={itemName,itemCharge}
              itemCharges+=el.itemCharge
              discountCharge+=el.discountCharge
              benefitCharge+=el.benefitCharge
              realityCharge+=el.realityCharge
              return obj
            })
            itemCharges=itemCharges.toFixed(2)+'元'
            discountCharge=discountCharge.toFixed(2)+'元'
            benefitCharge=benefitCharge.toFixed(2)+'元'
            big_realityCharge=this.digitUppercase(realityCharge)
            realityCharge=realityCharge.toFixed(2)+'元'

            let chargeItemStr =
              "<tr style='border-style: none;height:25px;'>" +
              "<td style='width: 115px'>服务项目</td><td style='60px'>应收</td>" +
              "<td style='width: 115px'>服务项目</td><td style='60px'>应收</td>" +
              "<td style='width: 115px'>服务项目</td><td style='60px'>应收</td>" +
              "<td style='width: 115px'>服务项目</td><td style='60px'>应收</td>" +
              "<td style='width: 115px'>服务项目</td><td style='60px'>应收</td></tr><tr style='border-style: none;height:25px;'>";
            if (chargeItems && chargeItems.length > 0) {
              let item = null;
              for (let k = 0; k < chargeItems.length; k++) {
                item = chargeItems[k];
                chargeItemStr +=
                  "<td>" + item.itemName + "</td><td>" + (item.itemCharge).toFixed(2) + "</td>";
                if (k != 0 && (k+1) % 5 == 0&&k!=chargeItems.length-1) {
                  chargeItemStr += "</tr><tr style='height:35px;'>";
                }
                if (k==chargeItems.length-1&&(k+1)%5!=0){
                  for(let kk=0;kk<(5-(k+1)%5);kk++){
                    chargeItemStr+="<td>&nbsp;</td><td>&nbsp;</td>";

                  }
                }
              }
              chargeItemStr += "</tr>";
            }
            let discountChargeItems = printData.discountChargeItems;
            let jianMainStr = "<tr style='height:25px;'>";
            if (discountChargeItems && discountChargeItems.length > 0) {
              let jianMainItem = null;
              for (let j = 0; j < discountChargeItems.length; j++) {
                jianMainItem = discountChargeItems[j];
                jianMainStr += jianMainItem.itemName + jianMainItem.itemPrice;
              }
            }
            jianMainStr += "</tr>";

            //制单日期
            let printTime = "制单日期：" + printData[0].takeBillDate.slice(0, 19).replace('T', ' ');
            //应收
            let yingShou = "应收：" + itemCharges;
            let huiMin = "减免：" + benefitCharge; //"优惠减免："+ printData.benefitTotalCharge;
            //费用减免
            let chargeJianMian = "0";
            if (printData.discountTotalCharge != null && printData.discountTotalCharge.trim().length != 0) {
              chargeJianMian = printData.discountTotalCharge;
            }
            chargeJianMian = "费用减免：" + chargeJianMian;
            //实收
            let activeCharge = "实收：" + realityCharge;
            //大写
            let realityTotalChargeText = "大写：" + big_realityCharge;
            //制单人
            let markMan = "制单人：" + printData[0].userFullName;
            let beforeDeathAddress = printData.beforeDeathAddress;

            let dataTable="<table class='tbl' align='center' cellpadding='0' cellspacing='0' width='720px' border='1' style='text-align: center ;border-collapse: collapse;font-size: 10pt;'>"+
              chargeItemStr+
              "<tr style='height:25px;'><td colspan='10'>" + yingShou + "&nbsp;&nbsp;" + huiMin + "&nbsp;&nbsp;" + activeCharge +"&nbsp;&nbsp;<br/>"+ realityTotalChargeText + "</td></tr>"+
              "</table>";
            dataTable+="<table align='center' width='720px'><tr><td width='450px'>"+printTime+"</td><td>"+markMan+"</td></tr></table>";

            let theTitle="<p style='font-size:20px;font-weight: bold; width: 700px;height: 80px;text-align: center'>" + title + "</p>"
            //纸张
            LODOP.SET_PRINT_PAGESIZE(1, 0,0, "A4");
            //设置字体
            LODOP.SET_PRINT_STYLE("FontSize", 11);
            //调用打印控件进行测试
            LODOP.ADD_PRINT_BARCODE("4mm", "160mm", "28mm", "28mm", "QRCode", recCode);
            LODOP.SET_PRINT_STYLEA(0, "QRCodeVersion", 2);
                  LODOP.SET_PRINT_STYLEA(0, "DataCharset", "UTF-8");
            LODOP.ADD_PRINT_HTM( 10,20,"100%",600, theTitle+dataTable);
            LODOP.ADD_PRINT_TEXT(50, "15mm", 500, 25, "业务编号：" + businessCode);
            LODOP.ADD_PRINT_TEXT(70, "15mm", 600, 25, "逝者姓名：" + deadName + ",  依次付款方式：" + selltedType + "\n收费日期：" + businessTime.slice(0, 19).replace('T', ' '));
            LODOP.SET_SHOW_MODE("SHOW_SCALEBAR", false);
            //打印预览
            LODOP.PREVIEW();
          },
          //业务查询显示
          businessSearchShow() {
              this.DialogSearch = true;
          },
          selectChange() {
              //给业务编码设置焦点
              this.$refs.deathChange_ref.blur();
              this.$refs.servicebusinessCode.focus();
         },
        //数据读取
        searchData(code){
          code=this.businessCode;
          let this_search=this;
          if (!code) {
            this_search.$message("请输入业务编码");
            return
          }
          this_search.loading = true
          this_search.$store.dispatch('user/setbusinessCode',this_search.businessCode).catch(()=>console.log('promise catch err'));
          let postData = {
            "businessCode": code,
            "dictTypeCodes": [
              "cremation_certificate_printing_operation_type"
            ]
          }

          Type['loadcremationcertificateprintingall'](postData).then(response => {

            if(!response){
              this_search.loading = false
              this.$store.commit('user/SET_BUSINESSCODE', '')
              this.reload()
              return;
            }

            const { data }=response;
            if (!data) {

              this_search.$message('数据读取失败')
              this_search.loading = false
              return
            }
             //数据读取成功
            if (data.funeralDead) {
              this_search.ruleForm.funeralDead = data.funeralDead
            }
            if (data.familyMember) {
              this_search.ruleForm.familyMember = data.familyMember
            }
            if (data.familyAgent) {
              this_search.ruleForm.familyAgent = data.familyAgent
            }
            if (data.dicts) {
              this_search.ruleForm.dicts = data.dicts
            }
            if (data.printHistory) {
              this_search.ruleForm.printHistory = data.printHistory
            }
            if(data.cremation.id){
              this_search.cremation.id=data.cremation.id
              this_search.cremation.cremationVersion=data.cremation.version
            }
            this_search.loading = false
          }).catch(error => {

            this_search.$message(error)
            this_search.loading = false
          })
          // this.businessCode="";
        },
        operationType(code){    //重打用原号码，发证重新填写
          let chongdaCode = 0,fazhengCode = 0
          this.dictionary.cremation_certificate_printing_operation_type.forEach(item=>{
            if (item.dataText.indexOf("重打")>-1) {
              chongdaCode = item.dataCode
            }if (item.dataText.indexOf("发证")>-1) {
              fazhengCode = item.dataCode
            }
          })
          if (this.saveCertificate.operationTypeCode == fazhengCode){   //发证
            this.saveCertificate.cremationNewNo = ""
            this.ruleForm.familyMember.certificateTypeCode=fazhengCode
          }else if (this.saveCertificate.operationTypeCode == chongdaCode){  //重打
            this.saveCertificate.cremationNewNo = JSON.parse(JSON.stringify(this.ruleForm.cremation.cremationNo))
            this.ruleForm.familyMember.certificateTypeCode=chongdaCode
          }

        },
        onSubmit(){
          this.$message('暂无生成规则')
        },
        saveData(){
          if ((Date.now() - this.onpresscTime) > 2000) {
            this.onpresscTime = Date.now()
          }else{
            return
          }
          let this_save=this;
            if (!this_save.businessCode) {
              this_save.$message("请输入业务编码");
              return
            }
            /*验证重打时原因不能为空*/
            if (this_save.saveCertificate.operationTypeCode=='2' && !this_save.saveCertificate.operationCause) {
              this_save.$message("重打时原因不能为空")
              return
            }
            if (!this_save.saveCertificate.operationTypeCode) {
              this_save.$message("操作类型不能为空")
              return
            }
            let postData = {
              "businessCode":this_save.businessCode,
              "memberId": this_save.ruleForm.familyMember.id,
              "memberVersion": this_save.ruleForm.familyMember.version,
              "operationTypeCode": this_save.saveCertificate.operationTypeCode,
              "operationTime": "",
              "operationCause": this_save.saveCertificate.operationCause,
              "cremationOldNo": this_save.ruleForm.cremation.cremationNo,
              "cremationNewNo": this_save.saveCertificate.cremationNewNo,
              "cremationId":this_save.cremation.id,
              "cremationVersion":this_save.cremation.cremationVersion
            }
          this.saveFlag = true;
            Type['savecremationcertificateprinting'](postData).then(response => {
              if(!response){
                this.saveFlag = false;
                return
              }
              const { data }=response;
              if (!data) {
                this_save.$message('数据读取失败')
                return
              }
              //   //数据读取成功
              this_save.$message('数据保存成功')
              //查询
              this_save.searchData(this_save.businessCode)
              this_save.saveFlag = false;
              this_save.loadCremationCertificate();
             //刷新
            }).catch(error => {
              this_save.$message(error)
              this.saveFlag = false;
            })
        },
        //补打火化证
        rePrintCert(){
          if ((Date.now() - this.onpresscTime) > 2000) {
            this.onpresscTime = Date.now()
            //console.log(Date.now())
          }else{
            return
          }
          let this_save=this;
          if (!this_save.businessCode) {
            this_save.$message("请输入业务编码");
            return
          }
          let postData = {
            "businessCode":this_save.businessCode,
            "memberId": this_save.ruleForm.familyMember.id,
            "memberVersion": this_save.ruleForm.familyMember.version,
            "operationTypeCode": 3,
            "operationTime": "",
            "operationCause": this_save.saveCertificate.operationCause,
            "cremationOldNo": this_save.ruleForm.cremation.cremationNo,
            "cremationNewNo": this_save.saveCertificate.cremationNewNo,
            "cremationId":this_save.cremation.id,
            "cremationVersion":this_save.cremation.cremationVersion
          }
          this.saveFlag = true;
          Type['savecremationcertificateprinting'](postData).then(response => {
            if(!response){
              //this_save.$message('数据保存失败')
              this.saveFlag = false;
              return
            }
            const { data }=response;
            if (!data) {
              this_save.$message('数据读取失败')
              return
            }
            //   //数据读取成功
            this_save.$message('数据保存成功')
            //查询
            this_save.searchData(this_save.businessCode)
            this_save.saveFlag = false;
            //查询火化证接口数据
            let this_print=this;
            let postData = {
              "businessCode": this_print.businessCode
            }
            Type['loadPrintCremationCertificate'](postData).then(response => {
              //接收返回数据
              let result = response.data;
              //调用打印接口
              this_print.rePrintCremationCertificate(result);
            }).catch(error => {
              this_print.$message(error)
            })
            //刷新
          }).catch(error => {
            this_save.$message(error)
            this.saveFlag = false;
          })
        },
        //载入火化证信息
         loadCremationCertificate(){
           //查询火化证接口数据
           let this_print=this;
           let postData = {
             "businessCode": this_print.businessCode
           }
           Type['loadPrintCremationCertificate'](postData).then(response => {
             //接收返回数据
             let result = response.data;
             if (result.cremationNo.substring(0,1)=="W") {
               //调用打印接口
               this_print.printCremationCertificate(result);
             }else
             {
               //调用打印接口
               this_print.rePrintCremationCertificate(result);
             }
           }).catch(error => {
             this_print.$message(error)
           })
         },
        //打印火化证
        printCremationCertificate(printData){
          let this_print=this;
          let LODOP =  getLodop();
          if (LODOP == null || !LODOP) {
            this_print.$.messager.alert('系统提示', '您的浏览器不支持打印控件，请用IE重试或安装打印控件后重试');
            return;
          }


      for (let key in printData) {
        printData[key] = printData[key]
          ? printData[key]
          : "　";
      }
          //当前业务时间
          let  businessCode=printData.businessCode;
          //火化证号
          let  cremationNo=printData.cremationNo;
          //逝者姓名
          let  deadName= printData.deadName;
          //逝者性别
          let  deadGender=printData.deadGender;
          //逝者年龄
          let  deadAge="年龄："+printData.deadAge;
          //户口所在地
          //证件类型
          let certificateTypeCode=printData.certificateType;
          //逝者证件号码
          let certificateNo=printData.certificateNo;
          //火化时间
          let appointmentDate=printData.appointmentDate;
          //领证人
          let thisMemberName=printData.memberName;
          //生前住址
          let beforeDeathAddress=printData.beforeDeathAddress ;
          let dataTable="　　逝者姓名: "+deadName+",　 性别:　"+deadGender+"  ,"+deadAge+",　 身份证类型:" +certificateTypeCode +
          　",证件号码:　"+certificateNo+",　逝者编号:　"+businessCode +
            ",生前地址: "+beforeDeathAddress+", 已于"+appointmentDate+"日在本单位火化。 ";

          let butoom1="发证单位(盖章):";
          let jingBan="经办人(签字):";
          let party="临沂市殡仪馆";
          let gaizhang="（火化专用章）";
          let date = dataFormatetmd1(new Date());
          let tel="　　 　发证单位电话:0536-5651654";
          //设置字体
          LODOP.SET_PRINT_STYLE("FontSize", 12);

          //打印标题
          LODOP.ADD_PRINT_TEXT(140,250,650,28,"证明编号："+cremationNo);
          LODOP.SET_PRINT_STYLEA(0,"FontSize",14);
          LODOP.SET_PRINT_STYLEA(0,"FontName","黑体");
          //打印协议
          LODOP.ADD_PRINT_TEXT(170,50,580,200,dataTable);
          LODOP.ADD_PRINT_TEXT(260,72,250,60,"  特此证明。");
          LODOP.ADD_PRINT_TEXT(280,30,300,60,"  领证人: "+thisMemberName);
          //发证单位
          LODOP.ADD_PRINT_TEXT(300,470,650,50,party);
          //经办人
          LODOP.ADD_PRINT_TEXT(328,462,650,50,gaizhang);
           LODOP.SET_PRINT_STYLEA(0,"FontSize",10);
          LODOP.ADD_PRINT_TEXT(370,460,650,50,date);
          LODOP.ADD_PRINT_TEXT(390,375,650,50,tel);
          //打印预览
          LODOP.PREVIEW();
        },//补办火化证
        rePrintCremationCertificate(printData){
          let this_print=this;
          let LODOP =  getLodop();
          if (LODOP == null || !LODOP) {
            this_print.$.messager.alert('系统提示', '您的浏览器不支持打印控件，请用IE重试或安装打印控件后重试');
            return;
          }
          for (let key in printData) {
            printData[key] = printData[key]
              ? printData[key]
              : "　";
          }
          //当前业务时间
          let  businessCode=printData.businessCode;
          //火化证号
          let  cremationNo=printData.cremationNo;
          //业务编码
          let  firstParty="<h1>补　办　火　化　证　明</h1>";
          //逝者姓名
          let  deadName= printData.deadName;
          //逝者性别
          let  deadGender=printData.deadGender;
          //逝者年龄
          let  deadAge="年龄："+printData.deadAge;
          //户口所在地
          //证件类型
          let certificateTypeCode=printData.certificateType;
          //逝者证件号码
          let certificateNo=printData.certificateNo;
          //火化时间
          let appointmentDate=printData.appointmentDate;
          //领证人
          let thisMemberName=printData.memberName;

          //生前住址
          let beforeDeathAddress=printData.beforeDeathAddress ;
          let dataTable="　　逝者姓名: "+deadName+",　 性别:　"+deadGender+"  ,"+deadAge+",　 身份证类型:" +certificateTypeCode +
          　",证件号码:　"+certificateNo+",　逝者编号:　"+businessCode +
            ",生前地址: "+beforeDeathAddress+", 已于"+appointmentDate+"日在本单位火化。 ";

          let butoom1="发证单位(盖章):";
          let jingBan="经办人(签字):";
          let party="临沂市第二殡仪馆";
          let gaizhang="（火化专用章）";
          let date = dataFormatetmd1(new Date());
          let tel="　　 　发证单位电话:0536-5651654";
          //纸张
          LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
          //设置字体
          LODOP.SET_PRINT_STYLE("FontSize", 12);

          //打印标题
          LODOP.ADD_PRINT_HTM(50,150,650,25,firstParty);
          LODOP.ADD_PRINT_BARCODE("4mm", "160mm", "28mm", "28mm", "QRCode", printData.businessCode);
          LODOP.SET_PRINT_STYLEA(0, "QRCodeVersion", 2);
          LODOP.SET_PRINT_STYLEA(0, "DataCharset", "UTF-8");
          LODOP.ADD_PRINT_TEXT( "27mm", "140mm", 300,25,"业务编码：" + printData.businessCode);
          //调用打印控件进行测试
          LODOP.ADD_PRINT_TEXT(150,250,650,28,"证明编号："+cremationNo);
          LODOP.SET_PRINT_STYLEA(0,"FontSize",14);
          LODOP.SET_PRINT_STYLEA(0,"FontName","黑体");
          //打印协议
          LODOP.ADD_PRINT_TEXT(180,50,650,200,dataTable);
          LODOP.ADD_PRINT_TEXT(260,72,250,60,"  特此证明。");
          LODOP.ADD_PRINT_TEXT(280,30,300,60,"  领证人: "+thisMemberName);
          LODOP.ADD_PRINT_TEXT(350,30,650,100,"声明：此证明仅证明逝者在临沂市第二殡仪馆火化，发生的任何法律后果与临沂市第二殡仪馆无关\n");
          //打印预览
          LODOP.PREVIEW();
        },
        PhotoArchival(){
          this.$router.push('/PhotoArchival')
        }, //根据文本返回字典code值
        CodeInString(search_str,searchArry){
          if (search_str && searchArry.length>0) {
            searchArry.forEach(item => {
              if (item.dataText.indexOf(search_str) >-1) {
                return item.dataCode
              }
            })
          }

        }
      },
    }
</script>
<style>
  .PrintReplace .textarea  .el-form-item__content{
    width:60vw;
  }
  .PrintReplace  .PageContent .new .el-input{
    width: 15vw;
  }
</style>
<style scoped>
  .el-form-item {
    margin-bottom: 10px !important;
  }
  .border1{
    border:1px solid #e2dada;
    padding:10px;
  }
  .marginright50{
    margin-right: 50px;
  }

</style>
